common={
	initCatalogueMagePage:function(){
		// 绑定dom对象
		this.obj = {
			searchText:$('#searchText'),
		};
		// 声明全局变量
		this.vars = {
			iIndex:0,
		};
		this.innnerHtml();
		this.btnEvent();
    this.initLoginPage();
	},
	innnerHtml:function(){
		var widthbox=$(".containner").height();
		$(".containner").width(widthbox);
  },
  initLoginPage:function() { // 登陆页初始化用户名回填
    var checked = window.localStorage.getItem("checked");
    if (checked) {
      var username = window.localStorage.getItem("username");
      var password = window.localStorage.getItem("password");
      $(".login_dlmm input[type='checkbox']").prop("checked",checked);
      $(".login_pssword input").val(password);
      $(".login_user input").val(username);
    } else {
      $(".login_pssword input").val("");
      $(".login_user input").val("");
    }
  },
  userLogin() {
    var username = $(".login_user input").val();
    var password = $(".login_pssword input").val();
    var checkedd = $(".login_dlmm input[type='checkbox']").prop("checked");
    var storage=window.localStorage;
    if (!username || !password) {
      alert("用户名或密码不能为空！");
      return false;
    }
    jrequest.post("/api/authenticate",{userName: username,password: password}).then(res => {
      var code = res.data.code;
      var msg = res.data.msg;
      if (code === 0) {
        storage.setItem("loginStatus","login");
        storage.setItem("userId",res.data.data.userId);
        if (checkedd) {
          storage["checked"] = checkedd;
          storage.setItem("username",username);
          storage.setItem("password",password);
        }
        window.location.href="index.html";
      } else {
        alert(msg);
        $(".login_pssword input").val("");
      }
    })
  },
	btnEvent:function(){
		var iIndex = 0;
		setInterval( function(){
			autoLoop();
		}, 10000 );
		function toggleSlide () {
			$("ul.login_menu li").eq(iIndex).show(500).siblings("li").hide(500);
			$(".login_imgtb ul li").eq(iIndex).addClass("login_activeAnimate").siblings("li").removeClass("login_activeAnimate")
		}

		function autoLoop () {
			iIndex++;
			if ( iIndex == $("ul.login_menu li").length ) {
				iIndex = 0;
			}
			toggleSlide();
    };

		$("#buttond").off("click").click(function(){ // 用户登陆
      common.userLogin();
    })
    $(".login_pssword input[type='password']").bind('keydown', function (event) {
      var event = window.event || arguments.callee.caller.arguments[0];
      if (event.keyCode == 13){
          common.userLogin();
      }
  });

    $(".login_dlmm input[type='checkbox']").change(() => { // 取消勾选删除storange数据
      var checked = $(".login_dlmm input[type='checkbox']").prop("checked");
      if (!checked) {
        window.localStorage.removeItem("username");
        window.localStorage.removeItem("password");
        window.localStorage.removeItem("checked");
      }
    })
	},

}

$(function(){
	common.initCatalogueMagePage();
});
